
local lianke = fk.CreateSkill {
  name = "lingling__lianke",
}

Fk:loadTranslationTable{
  ["lingling__lianke"] = "连克",
  [":lingling__lianke"] = "出牌阶段，若本回合没有基本牌进入弃牌堆，你可以将一张牌当【过河拆桥】或无次数限制的【杀】使用，若为交替使用，你摸一张牌。",

  ["#lingling__lianke"] = "连克：你可以将一张牌当【过河拆桥】或无次数限制的【杀】使用",
}

lianke:addEffect("viewas", {
  anim_type = "offensive",
  mute_card = false,
  prompt = "#lingling__lianke",
  interaction = function(self, player)
    local all_names = {"dismantlement", "slash"}
    local names = player:getViewAsCardNames(lianke.name, all_names)
    if #names == 0 then return end
    return UI.CardNameBox { choices = names, all_choices = all_names }
  end,
  handly_pile = true,
  card_filter = function(self, player, to_select, selected)
    return #selected == 0
  end,
  view_as = function(self, player, cards)
    if #cards ~= 1 or self.interaction.data == nil then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = lianke.name
    card:addSubcard(cards[1])
    return card
  end,
  before_use = function (self, player, use)
    use.extraUse = true
    if player:getMark("lingling__lianke-phase") ~= 0 and
      use.card.name ~= player:getMark("lingling__lianke-phase") then
      player:drawCards(1, lianke.name)
    end
    player.room:setPlayerMark(player, "lingling__lianke-phase", use.card.name)
  end,
  enabled_at_play = function (self, player)
    return player:getMark("lingling__lianke-turn") == 0
  end,
})

lianke:addEffect("targetmod", {
  bypass_times = function(self, player, skill, scope, card, to)
    return card and table.contains(card.skillNames, lianke.name)
  end
})

lianke:addEffect(fk.AfterCardsMove, {
  can_refresh = function(self, event, target, player, data)
    if player:hasSkill(lianke.name, true) and player.room.current == player and
      player:getMark("lingling__lianke-turn") == 0 then
      for _, move in ipairs(data) do
        if move.toArea == Card.DiscardPile then
          for _, info in ipairs(move.moveInfo) do
            if Fk:getCardById(info.cardId).type == Card.TypeBasic then
              return true
            end
          end
        end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "lingling__lianke-turn", 1)
  end,
})

return lianke
